Repository navigation
fix(hooks): decline when a worktree has no dependencies - #1095
Conversation
`git worktree add` never runs `prepare`, so a factory worktree arrives with neither `.husky/_` nor `node_modules`; the `. _/husky.sh` source then aborted every commit with rc 1 before any gate ran. Six tool-call rows across four days were that failure, each paid as a discovery of `--no-verify`. Both hooks now decline when there are no dependencies to lint or test, and source the shim only when it exists. A checkout that can run its gates runs them unchanged - verified in a fresh worktree: commit rc 0 with no deps, and the shim plus `pnpm run lint` still ran once they were present.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
[Medium impact] The PR appears safe to merge.
|
`pre-commit` runs three commands, so without `set -e` the hook's exit status is `test:unit`'s alone and a failing lint is swallowed by a passing test run. The guard goes after the shim line rather than before it: `[ -f … ] && . …` returns 1 when the shim is absent, and under `set -e` that aborts the commit — the worktree case this file exists to fix. Measured with a stub `pnpm` whose `lint` fails: the base hook and this branch's previous head both exit 0; with the guard the hook exits 1, and a checkout with no `node_modules` still exits 0. Reported by Greptile on #1095.
What was wrong
A factory worktree cannot commit.
git worktree adddoes not runprepare, so the new checkout has neither.husky/_nornode_modules, and the first line of both hooks aborts:shexits a non-interactive script when a.fails, so no gate ever runs and the commit never happens. The workaround every agent finds is--no-verify, which skips the gates the hooks exist to enforce.Six tool-call rows across 2026-11-06..09 were this failure, from both the primary and job subagents, all inside
projects/nostream-worktrees/*.What this changes
Both hooks now decline when the checkout has nothing to run, and source the shim only when it exists:
A checkout that can run its gates is unchanged:
pnpm run lint,build:check,test:unitandcommitlintstill run, and still block on failure.Verified in a fresh worktree off this base
node_modules, no.husky/_rc=1, no commitrc=0, commit landsnode_modules+.husky/_presentHOOK-RAN),pnpm run lintexecutesOut of scope
The deeper cause is that a worktree is expected to install before committing. Making
preparerun per worktree would put a full dependency install on every factory job, so declining is the cheaper and more honest behaviour for a checkout with no dependencies: there is nothing for the gates to check against.